#include "Image.h"
//#include "wxImageLoader.h"



Image::Image()
{
}
 
Image::Image(char* path)
{
    logger = new Logger("Image.txt");
    page_num = 0;
    load(path);
}
 
void Image::load(char* path)
{
    char temp_log[100] = {0,};
    //ID = loadImage(path, &width, &height, &textureWidth, &textureHeight);
    
    width = 512;
    height = 512;
    
    muPDFManager = new MuPDFManager(width,height);
    page_num = muPDFManager->openPDFFile(path);
    sprintf(temp_log,"page num : %d",page_num);
    logger->printLog(temp_log);
    
    // Alloc ID_list 
    ID_List = (GLuint**)malloc(sizeof(GLuint*) * page_num);
    pdf_pages = (PDFPage**)malloc(sizeof(PDFPage*) * page_num);
    
    for(int i = 0;  i < page_num ; i++){
        ID_List[i] = muPDFManager->loadImage(i+1,&imageWidth,&imageHeight,&textureWidth,&textureHeight);
        //pdf_pages[i]->texture_ID = muPDFManager->loadImage(i+1,&imageWidth,&imageHeight,&textureWidth,&textureHeight);
    }
    //ID = muPDFManager->loadImage(12, width,height,&textureWidth,&textureHeight);
    
    
    tex_coord_x = (float)imageWidth/(float)textureWidth;
    tex_coord_y = (float)imageHeight/(float)textureHeight;
}
 
GLuint* Image::getID()
{
    return ID;
}

GLuint* Image::getID(int page_num)
{
    return ID_List[page_num];   
}

Image::~Image()
{
    glDeleteTextures (1, ID);
}
